package com.lzc.springcloud.msconsumeruser.feign;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import com.lzc.springcloud.msconsumeruser.entity.User;

import feign.hystrix.FallbackFactory;

@Component
public class HystrixClientFallbackFactory implements FallbackFactory<UserFeignClient> {
	
	private static final Logger LOGGER = LoggerFactory.getLogger(HystrixClientFallbackFactory.class);
	
	@Override
	public UserFeignClient create(Throwable cause) {
		
		HystrixClientFallbackFactory.LOGGER.info("HystrixClientFallbackFactory reason was: {}", cause.getMessage());
		
		return new UserFeignClientWithFallBackFactory() {

			@Override
			public User getUser(Integer id) {
				User user = new User();
				user.setName(cause.getMessage());
				return user;
			}

		};
	}

}
